﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

public partial class UserControl_Top2Advertis : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        StringBuilder sbRight = new StringBuilder();
        sb.Append("<script type='text/javascript'>");
        sb.Append("var advCenterLeft = new fadeSlideShow({wrapperid: 'advCenterLeft',dimensions: [270, 60],imagearray: [");

        sbRight.Append("<script type='text/javascript'>");
        sbRight.Append("var advCenterRight = new fadeSlideShow({wrapperid: 'advCenterRight',dimensions: [270, 60],imagearray: [");
        using (Up1VNDataContext dc = new Up1VNDataContext())
        {
            var top1 = from o in dc.UsersAdvs
                       where o.UsersAdv_Location == "footer" && o.UsersAdv_ToDate > DateTime.Now && o.UsersAdv_Status == (long)2
                       select o;
            if (top1.Count() > 0)
            {
                var item1 = top1.Take(top1.ToList().Count/2);
                foreach(var selectrow in item1)
                {
                    sb.Append("['" + ResolveUrl("~/images/Advertis/" + selectrow.UsersAdv_PicturePath) + "','" + selectrow.UsersAdv_Id + "/Thongtindoanhnghiep.html','','<a href=\"" + ResolveUrl("~/center/Dangquangcao.html") + "\">Đăng quảng cáo</a>'],");
                }
                var item2 = top1.Take(top1.ToList().Count).Skip(top1.ToList().Count / 2);
                foreach(var selectrow2 in item2)
                {
                    sbRight.Append("['" + ResolveUrl("~/images/Advertis/" + selectrow2.UsersAdv_PicturePath) + "','" + selectrow2.UsersAdv_Id + "/Thongtindoanhnghiep.html','','<a href=\"" + ResolveUrl("~/center/Dangquangcao.html") + "\">Đăng quảng cáo</a>'],");
                }
            }
            else
            {
                sb.Append("['" + ResolveUrl("~/images/add_avertis_small.gif") + "','','','<a href=\"" + ResolveUrl("~/center/Dangquangcao.html") + "\">Đăng quảng cáo</a>'],");
                sbRight.Append("['" + ResolveUrl("~/images/add_avertis_small.gif") + "','','','<a href=\"" + ResolveUrl("~/center/Dangquangcao.html") + "\">Đăng quảng cáo</a>'],");
            }
        }
        sb.Append("],displaymode: { type: 'auto', pause: 3000, cycles: 0, wraparound: false },persist: false,fadeduration: 500,descreveal: 'ondemand',togglerid: ''})");
        sb.Append("</script>");

        sbRight.Append("],displaymode: { type: 'auto', pause: 3000, cycles: 0, wraparound: false },persist: false,fadeduration: 500,descreveal: 'ondemand',togglerid: ''})");
        sbRight.Append("</script>");

        ltrcenterLeft.Text = sb.ToString();
        ltrcenterRight.Text = sbRight.ToString();
    }
}